import request from '../utils/request'
import {isEmpty} from '../utils/helpers'
import {Method} from 'axios'

export interface ApiOption {
    path: string,
    method?: Method
}

export interface ApiOptions {
    [key: string]: ApiOption,
}

export const http = function (api: ApiOption, params = {}) {
    if (!api || isEmpty(api.path)) {
        throw new Error('请求信息错误!!!')
    }
    const method = api.method || 'get'
    const isGet = method === 'get'
    return request(api.path, {
        method,
        data: isGet ? {} : params,
        params: isGet ? params : {}
    })
}


